package com.own.core.html.table;

import java.util.Arrays;
import java.util.List;

import org.apache.wicket.extensions.ajax.markup.html.repeater.data.table.AjaxFallbackDefaultDataTable;
import org.apache.wicket.extensions.ajax.markup.html.repeater.data.table.AjaxFallbackHeadersToolbar;
import org.apache.wicket.extensions.ajax.markup.html.repeater.data.table.AjaxNavigationToolbar;
import org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable;
import org.apache.wicket.extensions.markup.html.repeater.data.table.DefaultDataTable;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.ISortableDataProvider;
import org.apache.wicket.extensions.markup.html.repeater.data.table.NoRecordsToolbar;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.OddEvenItem;
import org.apache.wicket.model.IModel;

public class OwnAjaxFallbackDefaultDataTable extends DataTable {

	private static final long serialVersionUID = 1L;

	/**
	 * Constructor
	 * 
	 * @param id
	 *            component id
	 * @param columns
	 *            list of columns
	 * @param dataProvider
	 *            data provider
	 * @param rowsPerPage
	 *            number of rows per page
	 */

	public OwnAjaxFallbackDefaultDataTable(String id,
			final List<IColumn> columns, ISortableDataProvider dataProvider,
			int rowsPerPage) {
		this(id, columns.toArray((IColumn[]) new IColumn[columns.size()]),
				dataProvider, rowsPerPage);
	}

	/**
	 * Constructor
	 * 
	 * @param id
	 *            component id
	 * @param columns
	 *            array of columns
	 * @param dataProvider
	 *            data provider
	 * @param rowsPerPage
	 *            number of rows per page
	 */
	public OwnAjaxFallbackDefaultDataTable(String id, final IColumn[] columns,
			ISortableDataProvider dataProvider, int rowsPerPage) {
		super(id, Arrays.asList(columns), dataProvider, rowsPerPage);
		setOutputMarkupId(true);
		setVersioned(false);

		addTopToolbar(new AjaxFallbackHeadersToolbar(this, dataProvider));

		addBottomToolbar(new NoRecordsToolbar(this));
		addBottomToolbar(new  AjaxNavigationToolbar(this));
	}

	@Override
	protected Item newRowItem(String id, int index, IModel model) {
		return new OddEvenItem(id, index, model);
	}

}
